package net.hn.hnms.biz.gasext.dws.controller.feign;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.hn.hnms.biz.api.safety.gasext.domain.*;
import net.hn.hnms.biz.api.safety.location.model.OutLimitAlarmingInfoVO;
import net.hn.hnms.biz.gasext.dws.domain.DimCoalMineBasicInfoPo;
import net.hn.hnms.biz.gasext.dws.service.AqjkService;
import net.hn.hnms.biz.gasext.dws.service.DwdService;
import net.hn.hnms.biz.gasext.dws.service.RydwService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.redis.domain.SysOrganization;
import net.hn.hnms.sys.common.redis.domain.SysOrganizationVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/remoteDws")
@Api(value = "远程调用dws接口", tags = {"远程调用dws接口"})
public class RemoteDwsController {
    @Resource
    private AqjkService aqjkService;

    @Resource
    private RydwService rydwService;

    @Resource
    private DwdService dwdService;
    @GetMapping("getSafetyMonitoringLocl")
    @ApiOperation("大屏首页-安全检测（本地数据）")
    public R<SafetyMonitoringVo> getSafetyMonitoringLocl(@ApiParam("公司编码") String companyCode, @ApiParam("煤矿编码") String mineCode) {
//        SafetyMonitoringVo safetyMonitoring = aqjkService.getSafetyMonitoringLocl();
        SafetyMonitoringVo safetyMonitoring = dwdService.getSafetyMonitoringLocl(companyCode, mineCode);


        return R.ok(safetyMonitoring);
    }

    /**
     * 获取当天报警超限信息
     */
    @GetMapping("alarmInfoList")
    @ApiOperation("获取当天报警超限信息")
    public R<List<OutLimitAlarmingInfoVO>> alarmInfoList(@ApiParam("公司编码") String companyCode,@ApiParam("煤矿编码") String mineCode) {
//        List<OutLimitAlarmingInfoVO> outLimitAlarmingInfoVOS = aqjkService.alarmInfoList(mineCode);
        List<OutLimitAlarmingInfoVO> outLimitAlarmingInfoVOS = dwdService.alarmInfoList(companyCode,mineCode);
        if (outLimitAlarmingInfoVOS.isEmpty()) {
            return R.ok(new ArrayList<>());
        }
        return R.ok(outLimitAlarmingInfoVOS);
    }


    /**
     * 超员情况
     * @return R
     */
    @GetMapping("getOverstaffingSituation")
    @ApiOperation("大屏首页-超员情况")
    public R<List<OverstaffingSituationDwsVo>> getOverstaffingSituation(@ApiParam("公司编码") String companyCode, @ApiParam("煤矿编码") String mineCode) {
//        List<OverstaffingSituationDwsVo> personnelMonitoringVoList = rydwService.getOverstaffingSituation();
        List<OverstaffingSituationDwsVo> personnelMonitoringVoList = dwdService.getOverstaffingSituation(companyCode,mineCode);
        return R.ok(personnelMonitoringVoList);
    }




    /**
     * 获取大屏人员监测信息
     * @return R
     */
    @GetMapping("getPersonnelMonitoring")
    @ApiOperation("大屏首页-人员检测")
    public R<PersonnelMonitoringVo> getPersonnelMonitoring(@ApiParam("公司编码") String companyCode, @ApiParam("煤矿编码") String mineCode) {
//        PersonnelMonitoringVo personnelMonitoringVo = rydwService.getPersonnelMonitoring();
        PersonnelMonitoringVo personnelMonitoringVo = dwdService.getPersonnelMonitoring(companyCode,mineCode);
        return R.ok(personnelMonitoringVo);
    }

    @GetMapping("trail")
    @ApiOperation("人员入井后轨迹")
    public R<List<TrailVo>> trail(@ApiParam(value = "人员卡号", required = true) String staffCode, @ApiParam(value = "入井时间（yyyy-MM-dd HH:mm:ss）"
            , required = true) String inTime
            , String mineCode) {
//        List<TrailVo> trailVoList = rydwService.trail(staffCode, inTime, mineCode);
        List<TrailVo> trailVoList = dwdService.trail(staffCode, inTime, mineCode);
        return R.ok(trailVoList);
    }

    /**
     * 根据姓名获取当前煤矿人的轨迹
     * @param name
     * @param mineCode
     * @return
     */
    @GetMapping("getTrailByName")
    @ApiOperation("根据姓名和煤矿编码获取轨迹")
    public R<LeadInfoVO> getTrailByName(@ApiParam(value = "人员姓名", required = true) String name,String mineCode) {
        LeadInfoVO vo = dwdService.getTrailByName(name, mineCode);
        return R.ok(vo);
    }

    @GetMapping("getHisTrailByName")
    @ApiOperation("根据姓名和煤矿编码获取轨迹-历史轨迹")
    public R<LeadInfoVO> getHisTrailByName(@ApiParam(value = "人员姓名", required = true) String name,
                                        @ApiParam(value = "人员卡编码：非必填，填写可提高查询速度") String code,
                                        @ApiParam(value = "入井时间（yyyy-MM-dd HH:mm:ss）", required = true) String inTime,
                                        @ApiParam(value = "数据上传时间：填写可提高查询速度（yyyy-MM-dd HH:mm:ss）") String dataUpTime,
                                        String mineCode) {
        LeadInfoVO vo = dwdService.getHisTrailByName(name,code,inTime ,dataUpTime,mineCode);
        return R.ok(vo);
    }

    @GetMapping("selectCodeSubList")
    @ApiOperation("获取华能煤矿树结构")
    public R<SysOrganizationVo> selectCodeSubList() {
        SysOrganizationVo sysOrganizationVo = aqjkService.selectCodeSubList();
        return R.ok(sysOrganizationVo);
    }
    @GetMapping("selectGroupCodeSubList")
    @ApiOperation("获取煤业公司煤矿树结构")
    public R<List<SysOrganizationVo>> selectGroupCodeSubList() {
        List<SysOrganizationVo> sysOrganizationVo = aqjkService.selectGroupCodeSubList();
        return R.ok(sysOrganizationVo);
    }
    @GetMapping("selectCodeSubMineList")
    @ApiOperation("获取煤业公司煤矿列表结构")
    public R<List<SysOrganization>> selectCodeSubMineList() {
        List<SysOrganization> list = aqjkService.selectCodeSubMineList();
        return R.ok(list);
    }
    @GetMapping("selectDisasterList")
    @ApiOperation("获取煤业公司煤矿基本信息列表")
    public R<List<DimCoalMineBasicInfoVo>> selectDisasterList(@ApiParam("公司编码") String companyCode, @ApiParam("煤矿编码") String mineCode) {
        List<DimCoalMineBasicInfoPo> list = aqjkService.selectCodeSubMineInfoList(companyCode,mineCode);
        List<DimCoalMineBasicInfoVo> collect = list.stream().map(t -> {
            DimCoalMineBasicInfoVo dimCoalMineBasicInfoVo = new DimCoalMineBasicInfoVo();
            BeanUtil.copyProperties(t, dimCoalMineBasicInfoVo);
            return dimCoalMineBasicInfoVo;
        }).collect(Collectors.toList());
        return R.ok(collect);
    }
    @GetMapping("getTransfiniteStatistics")
    @ApiOperation("pc-大屏首页-超限统计")
    public R<TransfiniteStatisticsVo> getTransfiniteStatistics(@ApiParam("公司编码") String companyCode, @ApiParam("煤矿编码") String mineCode, @ApiParam(value = "查询类型：周或月，不传默认十天") String type) {
        TransfiniteStatisticsVo transfiniteStatisticsVo = aqjkService.getTransfiniteStatistics(companyCode,mineCode,type);
        return R.ok(transfiniteStatisticsVo);
    }
}
